/*
 * @(#)MtmWorkflowProgressUserRecord.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.Vector;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.AbstractDAObject;
import com.dcivision.framework.web.AbstractSearchForm;
import com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord;
import com.dcivision.workflow.bean.MtmWorkflowStepUserActor;
import com.dcivision.workflow.bean.WorkflowProgress;

/**
 * MtmWorkflowProgressUserRecordDAObject.java
 *
 * This class is the data access bean for table "MTM_WF_PROGRESS_USER_RECORD".
 *
 * @author      Rollo Chan
 * @company     DCIVision Limited
 * @creation date   07/10/2003
 * @version     $Revision: 1.42.2.2 $
*/

public class MtmWorkflowProgressUserRecordDAObject extends AbstractDAObject {

  public static final String REVISION = "$Revision: 1.42.2.2 $";

  public static final String TABLE_NAME = "MTM_WF_PROGRESS_USER_RECORD";

  public MtmWorkflowProgressUserRecordDAObject(SessionContainer sessionContainer, Connection dbConn) {
    super(sessionContainer, dbConn);
  }

  protected void initDBSetting() {
    this.baseTableName = TABLE_NAME;
    this.vecDBColumn.add("ID");
    this.vecDBColumn.add("WORKFLOW_PROGRESS_ID");
    this.vecDBColumn.add("USER_RECORD_ID");
    this.vecDBColumn.add("DELEGATE_USER_RECORD_ID");
    this.vecDBColumn.add("WORKFLOW_ACTION");
    this.vecDBColumn.add("REASON");
    this.vecDBColumn.add("RECORD_STATUS");
    this.vecDBColumn.add("UPDATE_COUNT");
    this.vecDBColumn.add("CREATOR_ID");
    this.vecDBColumn.add("CREATE_DATE");
    this.vecDBColumn.add("UPDATER_ID");
    this.vecDBColumn.add("UPDATE_DATE");
  }

  protected synchronized AbstractBaseObject getByID(Integer id) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID,A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, id);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          return(tmpMtmWorkflowProgressUserRecord);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized List getList(AbstractSearchForm searchForm) throws ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID,A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");

        // Form the WHERE clause for filtering.
        if (searchForm.isSearchable()) {
          String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }

        //format the sql for any 'LIKE' statement contained
        sqlStat = this.getFormattedSQL(sqlStat.toString());

        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append("ORDER BY " + sortAttribute + " " + searchForm.getSortOrder());
        }

        // Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString());
        this.setPrepareStatement(preStatCnt, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStatCnt, 2, searchKeyword);
        }
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }

        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStat, 2, searchKeyword);
        }
        rs = preStat.executeQuery();

        this.positionCursor(rs, startOffset, pageSize);

        while (rs.next() && rowLoopCnt<pageSize) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          tmpMtmWorkflowProgressUserRecord.setRecordCount(totalNumOfRecord);
          tmpMtmWorkflowProgressUserRecord.setRowNum(startOffset++);
          ++rowLoopCnt;
          result.add(tmpMtmWorkflowProgressUserRecord);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
      }
    }
  }

  protected synchronized List getList() throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID,A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          result.add(tmpMtmWorkflowProgressUserRecord);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected void validateInsert(AbstractBaseObject obj) throws ApplicationException {
  }

  protected void validateUpdate(AbstractBaseObject obj) throws ApplicationException {
  }

  protected void validateDelete(AbstractBaseObject obj) throws ApplicationException {
  }

  protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = (MtmWorkflowProgressUserRecord)((MtmWorkflowProgressUserRecord)obj).clone();

    synchronized(dbConn) {
      try {
        Integer nextID = getNextPrimaryID();
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("INSERT ");
        //sqlStat.append("INTO   MTM_WF_PROGRESS_USER_RECORD(ID, WORKFLOW_PROGRESS_ID, USER_RECORD_ID, DELEGATE_USER_RECORD_ID, WORKFLOW_ACTION, REASON, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE) ");//simon_del
        //sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?) ");//simon_del
        sqlStat.append("INTO   MTM_WF_PROGRESS_USER_RECORD(ID, WORKFLOW_PROGRESS_ID, USER_RECORD_ID, DELEGATE_USER_RECORD_ID, WORKFLOW_ACTION, REASON, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE, OPERATION_PARAMETER) ");//simon_add
        sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?) ");//simon_add
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, nextID);
        setPrepareStatement(preStat, 2, tmpMtmWorkflowProgressUserRecord.getWorkflowProgressID());
        setPrepareStatement(preStat, 3, tmpMtmWorkflowProgressUserRecord.getUserRecordID());
        setPrepareStatement(preStat, 4, tmpMtmWorkflowProgressUserRecord.getDelegateUserRecordID());
        setPrepareStatement(preStat, 5, tmpMtmWorkflowProgressUserRecord.getWorkflowAction());
        setPrepareStatement(preStat, 6, tmpMtmWorkflowProgressUserRecord.getReason());
        setPrepareStatement(preStat, 7, GlobalConstant.RECORD_STATUS_ACTIVE);
        setPrepareStatement(preStat, 8, new Integer(0));
        setPrepareStatement(preStat, 9, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 10, currTime);
        setPrepareStatement(preStat, 11, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 12, currTime);
        setPrepareStatement(preStat, 13, tmpMtmWorkflowProgressUserRecord.getOperationParameter());//simon_add
        preStat.executeUpdate();
        tmpMtmWorkflowProgressUserRecord.setID(nextID);
        tmpMtmWorkflowProgressUserRecord.setCreatorID(sessionContainer.getUserRecordID());
        tmpMtmWorkflowProgressUserRecord.setCreateDate(currTime);
        tmpMtmWorkflowProgressUserRecord.setUpdaterID(sessionContainer.getUserRecordID());
        tmpMtmWorkflowProgressUserRecord.setUpdateDate(currTime);
        tmpMtmWorkflowProgressUserRecord.setUpdateCount(new Integer(0));
        tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
        tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
        return(tmpMtmWorkflowProgressUserRecord);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_INSERT_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized AbstractBaseObject update(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = (MtmWorkflowProgressUserRecord)((MtmWorkflowProgressUserRecord)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE MTM_WF_PROGRESS_USER_RECORD ");
        //sqlStat.append("SET  WORKFLOW_PROGRESS_ID=?, USER_RECORD_ID=?, DELEGATE_USER_RECORD_ID=?, WORKFLOW_ACTION=?, REASON=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=?,");//simon_del
        sqlStat.append("SET  WORKFLOW_PROGRESS_ID=?, USER_RECORD_ID=?, DELEGATE_USER_RECORD_ID=?, WORKFLOW_ACTION=?, REASON=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=?, OPERATION_PARAMETER=? ");//simon_add
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpMtmWorkflowProgressUserRecord.getWorkflowProgressID());
        setPrepareStatement(preStat, 2, tmpMtmWorkflowProgressUserRecord.getUserRecordID());
        setPrepareStatement(preStat, 3, tmpMtmWorkflowProgressUserRecord.getDelegateUserRecordID());
        setPrepareStatement(preStat, 4, tmpMtmWorkflowProgressUserRecord.getWorkflowAction());
        setPrepareStatement(preStat, 5, tmpMtmWorkflowProgressUserRecord.getReason());
        setPrepareStatement(preStat, 6, new Integer(tmpMtmWorkflowProgressUserRecord.getUpdateCount().intValue() + 1));
        setPrepareStatement(preStat, 7, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 8, currTime);
        setPrepareStatement(preStat, 9, tmpMtmWorkflowProgressUserRecord.getOperationParameter());//simon_add
        setPrepareStatement(preStat, 10, tmpMtmWorkflowProgressUserRecord.getID());
        setPrepareStatement(preStat, 11, tmpMtmWorkflowProgressUserRecord.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(sessionContainer.getUserRecordID());
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(currTime);
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(new Integer(tmpMtmWorkflowProgressUserRecord.getUpdateCount().intValue() + 1));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          return(tmpMtmWorkflowProgressUserRecord);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized AbstractBaseObject delete(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = (MtmWorkflowProgressUserRecord)((MtmWorkflowProgressUserRecord)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpMtmWorkflowProgressUserRecord.getID());
        setPrepareStatement(preStat, 2, tmpMtmWorkflowProgressUserRecord.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          return(tmpMtmWorkflowProgressUserRecord);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized void auditTrail(String opMode, AbstractBaseObject obj) throws ApplicationException {
    Vector oldValues = new Vector();
    Vector newValues = new Vector();
    MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = (MtmWorkflowProgressUserRecord)this.oldValue;

    if (tmpMtmWorkflowProgressUserRecord != null) {
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getID()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getWorkflowProgressID()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getUserRecordID()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getDelegateUserRecordID()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getWorkflowAction()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getReason()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getRecordStatus()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getUpdateCount()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getCreateDate()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
      oldValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getUpdateDate()));
    }

    tmpMtmWorkflowProgressUserRecord = (MtmWorkflowProgressUserRecord)obj;
    if (tmpMtmWorkflowProgressUserRecord != null) {
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getID()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getWorkflowProgressID()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getUserRecordID()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getDelegateUserRecordID()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getWorkflowAction()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getReason()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getRecordStatus()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getUpdateCount()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getCreateDate()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
      newValues.add(toAuditTrailValue(tmpMtmWorkflowProgressUserRecord.getUpdateDate()));
    }

    auditTrailBase(opMode, oldValues, newValues);
  }

  /***********************************************************************
   * DON'T Modify the codes above unless you know what you are doing!!!  *
   * Put your own functions beblow.                                      *
   * For FINDER methods, the function name should be in the notation:    *
   *   public Object getObjectBy<Criteria>()                             *
   *   - e.g. public Object getObjectByCode()                            *
   *   public List getListBy<Criteria>()                                 *
   *   - e.g. public List getListByUserID()                              *
   * For OPERATION methods, the function name should be in the notation: *
   *   public void <Operation>ObjectBy<Criteria>()                       *
   *   - e.g. public void deleteObjectByCode()                           *
   *   public void <Operation>ListBy<Criteria>()                         *
   *   - e.g. public void deleteListByUserID()                           *
   ***********************************************************************/
  /**
   * Gets a list of progress user for given workflow progress
   * 
   * @param workflowProgressID The workflow progress ID
   * @return List of MtmWorkflowProgressUserRecord objects
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized List getListByWorkflowProgressID(Integer workflowProgressID) throws ApplicationException {
    return this.getListByWorkflowProgressID(workflowProgressID,null);
  }
  /**
   * Gets a list of progress user for given workflow progress
   * 
   * @param workflowProgressID The workflow progress ID
   * @return List of MtmWorkflowProgressUserRecord objects
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized List getListByWorkflowProgressID(Integer workflowProgressID,String workflowAction) throws ApplicationException {
    return this.getListByWorkflowProgressID(workflowProgressID,workflowAction,null);
  }
  /**
   * Gets a list of progress user of the given workflow progress ID
   * 
   * @param workflowProgressID The workflow progress ID
   * @return List of MtmWorkflowProgressUserRecord objects
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized List getListByWorkflowProgressID(Integer workflowProgressID,String workflowAction,String exceptWorkflowAction) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE,A.OPERATION_PARAMETER ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? AND WORKFLOW_PROGRESS_ID = ? ");
        if(!Utility.isEmpty(workflowAction)){
          sqlStat.append("AND WORKFLOW_ACTION = ? ");
        }
        if(!Utility.isEmpty(exceptWorkflowAction)){
          sqlStat.append("AND WORKFLOW_ACTION <> ? ");
        }
        sqlStat.append("ORDER BY UPDATE_DATE ASC ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        int i = 1;
        this.setPrepareStatement(preStat, i++, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, i++, workflowProgressID);
        if(!Utility.isEmpty(workflowAction)){
          this.setPrepareStatement(preStat, i++, workflowAction);
        }
        if(!Utility.isEmpty(exceptWorkflowAction)){
          this.setPrepareStatement(preStat, i++, exceptWorkflowAction);
        }
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          tmpMtmWorkflowProgressUserRecord.setUserRecordName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUserRecordID()));
          tmpMtmWorkflowProgressUserRecord.setOperationParameter(getResultSetString(rs,"OPERATION_PARAMETER"));
          result.add(tmpMtmWorkflowProgressUserRecord);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Gets a object of MtmWorkflowProgressUserRecord for given workflow progress and user record
   * 
   * @param workflowProgressID The workflow progress ID
   * @param userRecordID The user record ID
   * @return object of MtmWorkflowProgressUserRecord
   * @throws ApplicationException
   * @see com.dcivision.user.bean.UserRecord
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized MtmWorkflowProgressUserRecord getUserRouteObjectByWorkflowProgressIDUserRecordID(Integer workflowProgressID, Integer userRecordID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
    log.debug("the current workflowprocess and userRecordEd is>>>>>>>>>>>>>"+workflowProgressID.toString()+userRecordID.toString());
    synchronized(dbConn) {
      try {
        //sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");//simon_del
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.OPERATION_PARAMETER, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");//simon_add
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.WORKFLOW_PROGRESS_ID = ? AND A.USER_RECORD_ID = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, workflowProgressID);
        this.setPrepareStatement(preStat, 2, userRecordID);
        rs = preStat.executeQuery();
        if (rs.next()) {
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setOperationParameter(getResultSetString(rs,"OPERATION_PARAMETER"));//simon_add
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
        }
        return(tmpMtmWorkflowProgressUserRecord);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  /**
   * Gets a list of completed progress user of the given workflow progress
   * 
   * @param workflowProgressID The workflow progress ID
   * @return List of MtmWorkflowProgressUserRecord objects
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized List getCompletedUserProcessRecordByWorkflowProgressID(Integer workflowProgressID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List wfProgressUserRecordList = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.WORKFLOW_PROGRESS_ID = ? AND  A.RECORD_STATUS = ? AND A.WORKFLOW_ACTION <> ? AND A.WORKFLOW_ACTION <> ? AND A.WORKFLOW_ACTION <> ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, workflowProgressID);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 3, WorkflowProgress.STATUS_PENDING);
        this.setPrepareStatement(preStat, 4, WorkflowProgress.STATUS_IN_PROGRESS);
        this.setPrepareStatement(preStat, 5, WorkflowProgress.STATUS_LOCK);
        rs = preStat.executeQuery();
        while(rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          wfProgressUserRecordList.add(tmpMtmWorkflowProgressUserRecord);
        }
        return(wfProgressUserRecordList);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Gets a list of progress user of the given workflow progress ID
   * 
   * @param workflowProgressID The workflow progress ID
   * @return List of MtmWorkflowProgressUserRecord objects
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized List getUserProcessRecordByWorkflowProgressID(Integer workflowProgressID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List wfProgressUserRecordList = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.WORKFLOW_PROGRESS_ID = ? AND  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, workflowProgressID);


        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while(rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          wfProgressUserRecordList.add(tmpMtmWorkflowProgressUserRecord);
        }
        return(wfProgressUserRecordList);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Gets/Creates a progress user record of the given workflow progress for the given user
   * return a new object if does not find existing one
   * 
   * @param workflowProgressID The workflow progress ID
   * @param userRecordID The user record ID
   * @return  The existing progress user record if exist<br>
   *          A new blank record if not exist
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   * @see com.dcivision.user.bean.UserRecord
   * @see com.dcivision.workflow.bean.WorkflowProgress
   */
  public synchronized MtmWorkflowProgressUserRecord getPendingObjectByWorkflowProgressIDUserRecordID(Integer workflowProgressID, Integer userRecordID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE \n");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A \n");
        sqlStat.append("WHERE  A.WORKFLOW_PROGRESS_ID = ? \n");
        sqlStat.append("  AND A.USER_RECORD_ID = ? \n");
        sqlStat.append("  AND (A.WORKFLOW_ACTION = ? OR A.WORKFLOW_ACTION = ?) \n");
        sqlStat.append("  AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, workflowProgressID);
        this.setPrepareStatement(preStat, 2, userRecordID);
        this.setPrepareStatement(preStat, 3, WorkflowProgress.STATUS_PENDING);
        this.setPrepareStatement(preStat, 4, WorkflowProgress.STATUS_IN_PROGRESS);
        this.setPrepareStatement(preStat, 5, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
        }
        return(tmpMtmWorkflowProgressUserRecord);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Gets a list of progress user record of the given workflow progress, which the 
   * progress is still in pending state
   * 
   * @param workflowProgressID The workflow progress ID
   * @return List of progress user record
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  // return a list if does not find existing one
  public synchronized List getPendingObjectListByWorkflowProgressID(Integer workflowProgressID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List resultList = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.WORKFLOW_PROGRESS_ID = ? AND A.WORKFLOW_ACTION = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, workflowProgressID);
        this.setPrepareStatement(preStat, 2, WorkflowProgress.STATUS_PENDING);
        this.setPrepareStatement(preStat, 3, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          resultList.add(tmpMtmWorkflowProgressUserRecord);
        }
        return(resultList);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Gets a string of user record ID(s) by workflow progress for given a string of workflow progress ID array
   * 
   * @param workflowProgressIDAry The workflow progress ID array
   * @return string of user record ID(s) (eg: id1,id2,id3...)
   * @throws ApplicationException
   */
  public synchronized String getDistinctUserRecordIDByWorkflowProgressID(String workflowProgressIDAry) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    String result = "";

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  WORKFLOW_PROGRESS_ID IN ( "+workflowProgressIDAry+" ) ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

        rs = preStat.executeQuery();
        while (rs.next()) {
          if (Utility.isEmpty(result)){
            result = getResultSetInteger(rs, "ID").toString();
          }
          result = result + ", " +getResultSetInteger(rs, "ID");
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  /**
   * Gets a list of progress user record that is checked out of the given workflow progress
   * 
   * @param workflowProgressID The workflow progress ID
   * @return List of progress user record
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized List getCheckoutUserIDListByWorkflowProgressID(String workflowProgressID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT DISTINCT B.ID ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ,  USER_RECORD B ");
        sqlStat.append("WHERE  A.USER_RECORD_ID = B.ID AND ");
        sqlStat.append("A.WORKFLOW_ACTION = 'I' AND ");
        sqlStat.append("A.WORKFLOW_PROGRESS_ID = '" + workflowProgressID + "'");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

        rs = preStat.executeQuery();
        while (rs.next()) {
         result.add(this.getResultSetInteger(rs, "ID"));
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Deletes the progress user record that belongs to the specific workflow progresses
   * The String should be in a format "id1,id2,id3,id4"
   * 
   * @param workflowProgressIDAry Comma separated workflow progress ID(s)
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   */
  public synchronized void deleteByProgressIDAry(String workflowProgressIDAry) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD ");
        sqlStat.append("WHERE  WORKFLOW_PROGRESS_ID IN ( "+workflowProgressIDAry+" )  ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          //throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        }
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  /**
   * Gets a list of progress user record that is still pending for the given user
   * 
   * @param userRecordID The user record ID
   * @return List of progress user record
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   * @see com.dcivision.user.bean.UserRecord
   */
  public synchronized List getPendingObjectListByUserRecordID(Integer userRecordID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.USER_RECORD_ID = ? AND A.WORKFLOW_ACTION = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, userRecordID);
        this.setPrepareStatement(preStat, 2, WorkflowProgress.STATUS_PENDING);
        this.setPrepareStatement(preStat, 3, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          result.add(tmpMtmWorkflowProgressUserRecord);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Gets a list of finished progress user record of the given workflow progress
   * 
   * @param workflowProgressID The workflow progress ID
   * @return List of progress user record
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized List getFinishedProgressListByWorkflowProgressID(Integer workflowProgressID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE,A.OPERATION_PARAMETER  \n");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A \n");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? \n");
        sqlStat.append("  AND WORKFLOW_PROGRESS_ID = ? \n");
        sqlStat.append("  AND (A.WORKFLOW_ACTION <> ? AND A.WORKFLOW_ACTION <> ?) \n");
        sqlStat.append("ORDER BY UPDATE_DATE ASC ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, workflowProgressID);
        // Currently for dynamic assigned users, a pending status will be inserted to this table
        this.setPrepareStatement(preStat, 3, WorkflowProgress.STATUS_PENDING);
        this.setPrepareStatement(preStat, 4, WorkflowProgress.STATUS_IN_PROGRESS);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setOperationParameter(getResultSetString(rs, "OPERATION_PARAMETER"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          tmpMtmWorkflowProgressUserRecord.setUserRecordName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUserRecordID()));
          result.add(tmpMtmWorkflowProgressUserRecord);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  /**
   * Gets a list of processed (include checked out) progress user record
   * of the given workflow progress
   * 
   * @param workflowProgressID The workflow progress ID
   * @return List of progress user record
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized List getProcessedListByWorkflowProgressID(Integer workflowProgressID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        //sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");//simon_del
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.OPERATION_PARAMETER, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");//simon_add
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? AND A.WORKFLOW_PROGRESS_ID = ? ");
        sqlStat.append("AND    A.WORKFLOW_ACTION <> ? ");
        sqlStat.append("ORDER BY UPDATE_DATE ASC ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, workflowProgressID);
        this.setPrepareStatement(preStat, 3, WorkflowProgress.STATUS_PENDING);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setOperationParameter(getResultSetString(rs,"OPERATION_PARAMETER"));//simon_add
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          tmpMtmWorkflowProgressUserRecord.setUserRecordName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUserRecordID()));
          result.add(tmpMtmWorkflowProgressUserRecord);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  /**
   * Gets a list of pending/checked out progress user record of the given workflow progress
   * 
   * @param workflowProgressID The workflow progress ID
   * @return List of progress user record
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized List getPendingAndInProgressObjectListByWorkflowProgressID(Integer workflowProgressID) throws ApplicationException {
    return getPendingAndInProgressObjectListByWorkflowProgressIDAndUserRecordID ( workflowProgressID, null );
  }

  /**
   * Gets a list of pending/checked out progress user record of the given workflow 
   * progress and user record
   * 
   * @param workflowProgressID The workflow progress ID
   * @param userRecordID  The user record ID<br>
   *                      Pass null to ignore this criteria
   * @return List of progress user record
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized List getPendingAndInProgressObjectListByWorkflowProgressIDAndUserRecordID(Integer workflowProgressID, Integer userRecordID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List resultList = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID, A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.WORKFLOW_PROGRESS_ID = ? \n");
        sqlStat.append("  AND ( A.WORKFLOW_ACTION = ? OR A.WORKFLOW_ACTION = ?  ) \n");
        sqlStat.append("  AND A.RECORD_STATUS = ? \n");
        if ( userRecordID != null ) {
          sqlStat.append("  AND A.USER_RECORD_ID = ? \n");
        }
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, workflowProgressID);
        this.setPrepareStatement(preStat, 2, WorkflowProgress.STATUS_PENDING);
        this.setPrepareStatement(preStat, 3, WorkflowProgress.STATUS_IN_PROGRESS);
        this.setPrepareStatement(preStat, 4, GlobalConstant.RECORD_STATUS_ACTIVE);
        if ( userRecordID != null ) {
          this.setPrepareStatement(preStat, 5, userRecordID );
        }
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          resultList.add(tmpMtmWorkflowProgressUserRecord);
        }
        return(resultList);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  /**
   * Gets the workflow progress List by workflow progress reason
   * 
   * @param reason Theworkflow progress reason
   * @return List of workflow progress ID
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   */
  public synchronized List getProgressIDListByReason(String reason) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List resultList = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT DISTINCT A.WORKFLOW_PROGRESS_ID ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE   A.RECORD_STATUS = ? \n");
        sqlStat.append("  AND ").append(this.getSearchColumn("REASON")).append(" LIKE ? \n");

        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, this.getFormattedKeyword(reason, "LIKE"));

        rs = preStat.executeQuery();
        while (rs.next()) {
          resultList.add(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
        }
        return(resultList);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  /**
   * Gets the most wanted route by different action takers of the given workflow progress
   * 
   * @param workflowProgressID The workflow progress ID
   * @return The route Map containing the route and the corresponding count
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord#getWorkflowAction()
   */
  public synchronized Map getMostWantedRouteByProgressID ( Integer workflowProgressID ) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    Map routeMap = new TreeMap();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT WORKFLOW_ACTION, COUNT(*) AS ROUTE_COUNT \n");
        sqlStat.append("FROM MTM_WF_PROGRESS_USER_RECORD \n");
        sqlStat.append("WHERE WORKFLOW_PROGRESS_ID=? \n");        
        sqlStat.append("  AND WORKFLOW_ACTION IS NOT NULL AND WORKFLOW_ACTION <> ? \n");
        sqlStat.append("  AND OPERATION_PARAMETER IS NULL ");
        sqlStat.append("GROUP BY WORKFLOW_PROGRESS_ID, WORKFLOW_ACTION \n");        
        
        sqlStat.append(" UNION ");
        
        sqlStat.append("SELECT OPERATION_PARAMETER, COUNT(*) AS ROUTE_COUNT \n");
        sqlStat.append("FROM MTM_WF_PROGRESS_USER_RECORD \n");
        sqlStat.append("WHERE WORKFLOW_PROGRESS_ID=? \n");
        sqlStat.append("  AND WORKFLOW_ACTION IS NOT NULL AND WORKFLOW_ACTION <> ? \n");
        sqlStat.append("  AND OPERATION_PARAMETER IS NOT NULL \n");
        sqlStat.append("GROUP BY WORKFLOW_PROGRESS_ID, OPERATION_PARAMETER \n");
        
        sqlStat.append("ORDER BY ROUTE_COUNT DESC \n");
        
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, workflowProgressID);                
        this.setPrepareStatement(preStat, 2, WorkflowProgress.STATUS_IN_PROGRESS);
        this.setPrepareStatement(preStat, 3, workflowProgressID);
        this.setPrepareStatement(preStat, 4, WorkflowProgress.STATUS_IN_PROGRESS);
        
        rs = preStat.executeQuery();
        int routeCount = -1;
        while(rs.next()) {
          int tmpRouteCount = rs.getInt(2);
          if(tmpRouteCount > routeCount){
            routeCount = tmpRouteCount;
            routeMap.clear();
          }
          if(tmpRouteCount == routeCount){
            routeMap.put ( rs.getString(1), new Integer(routeCount) );
          }
        }
        return routeMap;
      } catch (SQLException sqle) {
log.error(sqle.getMessage(), sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
log.error(e.getMessage(), e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  /**
   * Gets system object by workflow progress and user record
   * 
   * @param progressID The workflow progress ID
   * @param userRecordID The user record ID
   * @return The system object(MtmWorkflowProgressUserRecord)
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgress
   */
  public synchronized AbstractBaseObject getObjectByWorkflowProgressIDUserRecordID(Integer workflowProgressID, Integer userRecordID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_PROGRESS_ID, A.USER_RECORD_ID,A.DELEGATE_USER_RECORD_ID, A.WORKFLOW_ACTION, A.REASON, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A ");
        sqlStat.append("WHERE  A.WORKFLOW_PROGRESS_ID = ? AND A.USER_RECORD_ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, workflowProgressID);
        this.setPrepareStatement(preStat, 2, userRecordID);
        this.setPrepareStatement(preStat, 3, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          MtmWorkflowProgressUserRecord tmpMtmWorkflowProgressUserRecord = new MtmWorkflowProgressUserRecord();
          tmpMtmWorkflowProgressUserRecord.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowProgressID(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
          tmpMtmWorkflowProgressUserRecord.setUserRecordID(getResultSetInteger(rs, "USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setDelegateUserRecordID(getResultSetInteger(rs, "DELEGATE_USER_RECORD_ID"));
          tmpMtmWorkflowProgressUserRecord.setWorkflowAction(getResultSetString(rs, "WORKFLOW_ACTION"));
          tmpMtmWorkflowProgressUserRecord.setReason(getResultSetString(rs, "REASON"));
          tmpMtmWorkflowProgressUserRecord.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWorkflowProgressUserRecord.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWorkflowProgressUserRecord.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWorkflowProgressUserRecord.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWorkflowProgressUserRecord.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWorkflowProgressUserRecord.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getCreatorID()));
          tmpMtmWorkflowProgressUserRecord.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWorkflowProgressUserRecord.getUpdaterID()));
          return(tmpMtmWorkflowProgressUserRecord);
        } else {
          return null;
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  /**
   * get in progress user name list by workflow progress ID.
   * @param workflowProgressID
   * @return List user name list
   * @throws ApplicationException
   */
  public synchronized List getInProgressUserNameListByWorkflowProgressID(Integer workflowProgressID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List resultList = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT B.FULL_NAME ");
        sqlStat.append("FROM   MTM_WF_PROGRESS_USER_RECORD A, ");
        sqlStat.append("       USER_RECORD B ");
        sqlStat.append("WHERE  A.WORKFLOW_PROGRESS_ID = ? \n");
        sqlStat.append("  AND A.WORKFLOW_ACTION = ? \n");
        sqlStat.append("  AND A.RECORD_STATUS = ? \n");
        sqlStat.append("  AND A.USER_RECORD_ID = B.ID ");
        
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, workflowProgressID);
        this.setPrepareStatement(preStat, 2, WorkflowProgress.STATUS_IN_PROGRESS);
        this.setPrepareStatement(preStat, 3, GlobalConstant.RECORD_STATUS_ACTIVE);
        
        rs = preStat.executeQuery();
        while (rs.next()) {
          resultList.add(getResultSetString(rs, "FULL_NAME"));
        }
        return(resultList);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  /**
   * get the completed progress ID string for the dynamic assign user step
   * @param userRecordID
   * @return String
   * @throws ApplicationException
   */
  public synchronized String getCompletedProgressIDListByUserRecordID(Integer userRecordID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    String progressIDs = "-1";
    synchronized(dbConn) {
      try {
        sqlStat.append(" SELECT DISTINCT A.WORKFLOW_PROGRESS_ID ");
        sqlStat.append(" FROM  MTM_WF_PROGRESS_USER_RECORD A, ");        
        sqlStat.append("       WORKFLOW_PROGRESS B, ");
        sqlStat.append("       WORKFLOW_STEP C, ");
        sqlStat.append("       MTM_WF_STEP_USER_ACTOR D ");
        sqlStat.append(" WHERE A.WORKFLOW_PROGRESS_ID = B.ID ");
        sqlStat.append(" AND   B.WORKFLOW_STEP_ID = C.ID ");
        sqlStat.append(" AND   A.RECORD_STATUS = ? ");
        sqlStat.append(" AND   C.WORKFLOW_RULE = '*' ");
        sqlStat.append(" AND   A.WORKFLOW_ACTION <> ? "); //P
        sqlStat.append(" AND   A.WORKFLOW_ACTION <> ? "); //I
        sqlStat.append(" AND   A.WORKFLOW_ACTION <> ? "); //L
        sqlStat.append(" AND   A.USER_RECORD_ID = ? ");
        sqlStat.append(" AND   D.ACTOR_TYPE = ? "); //D
        
        
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, WorkflowProgress.STATUS_PENDING);
        this.setPrepareStatement(preStat, 3, WorkflowProgress.STATUS_IN_PROGRESS);
        this.setPrepareStatement(preStat, 4, WorkflowProgress.STATUS_LOCK);
        this.setPrepareStatement(preStat, 5, userRecordID);
        this.setPrepareStatement(preStat, 6, MtmWorkflowStepUserActor.ACTOR_TYPE_RUNTIME_ASSIGN);
        
        rs = preStat.executeQuery();
        while (rs.next()) {
          progressIDs += "," + getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID").toString();
          //resultList.add(getResultSetInteger(rs, "WORKFLOW_PROGRESS_ID"));
        }
        return(progressIDs);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }  
}
